<?php
/**
 * titre-sejour/load-index.phtml
 */
?>
<?php
// Variables
$titres = $this->titres;
?>
<div class="list-container">
    <table class="table table-striped list-table">
	<thead>
	    <tr>

		<td width="45%">Libellé</td>
		<td width="45%">Description</td>
		<td width="10%">&nbsp;</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($titres as $t): ?>
    	    <tr>

    		<td><a href="#" class="edit-libelle" data-type="text" data-pk="<?php echo $t->id; ?>" data-name="libelle"><?php echo $t->libelle; ?></a></td>
    		<td><a href="#" class="edit-description" data-type="textarea" data-pk="<?php echo $t->id; ?>" data-name="description"><?php echo $t->description; ?></a></td>
    		<td>
    		    <a href='#' data-id="<?php echo $t->id; ?>" data-libelle="<?php echo $t->libelle; ?>" class="delete-x">
    			<img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
    		    </a>
    		</td>
    	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
</div>

<script type="text/javascript">
// Démarrage
    $(function() {
	// Edition des libellés
	$('.edit-libelle').editable({
	    title: 'Edition du libellé',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'titresejour', 'action' => 'save')); ?>'
	});
	// Edition des descriptions
	$('.edit-description').editable({
	    title: 'Edition de la description',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'titresejour', 'action' => 'save')); ?>'
	});
	// Effacer
	$('.delete-x').click(function(e) {
	    e.preventDefault();
	    libelle = $(this).attr('data-libelle');
	    id = $(this).attr('data-id');
	    if (!confirm("Voulez-vous effacer le titre de séjour '" + libelle + "' ?")) {
		return false;
	    }
	    ajax = $.ajax({
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'titresejour', 'action' => 'erase')) ?>',
		data: '&id=' + id
	    });
	    ajax.done(function(result) {
		if (!result.done) {
		    alert("Une erreur est survenue !");
		}
		refresh();
	    });
	});
    });
</script>
